package com.thirtydays.frame.ui.pop

import android.content.Context
import android.graphics.Color
import com.lxj.xpopup.core.CenterPopupView
import com.thirtydays.frame.R
import com.thirtydays.frame.databinding.DialogDeleteMachineConfirmBinding
import com.thirtydays.frame.util.ext.clicks

/**
 * @author 小垚
 * @创建时间： 2021/5/24
 * @描述： 居中弹窗
 **/
class CenterTipPopView(context: Context, successColor: Int, content: String, onCancel: () -> Unit, onSuccess: (CenterTipPopView) -> Unit) :
    CenterPopupView(context) {

    override fun getImplLayoutId(): Int {
        return R.layout.dialog_delete_machine_confirm
    }

    lateinit var viewBinding: DialogDeleteMachineConfirmBinding
    var mOnSuccess = onSuccess
    var mOnCancel = onCancel
    var mContent = content
    private var mSuccessColor = successColor
    override fun onCreate() {
        super.onCreate()
        viewBinding = DialogDeleteMachineConfirmBinding.bind(contentView)

        if (mSuccessColor != -1) {
            viewBinding.tvConfirm.delegate.rvbackgroundColor = mSuccessColor
            viewBinding.tvConfirm.delegate.rvbackgroundStartColor = Color.TRANSPARENT
            viewBinding.tvConfirm.delegate.rvbackgroundEndColor = Color.TRANSPARENT
        }


        viewBinding.tvContent.text = mContent
        viewBinding.tvCancel.clicks {
            dismiss()
            mOnCancel()
        }

        viewBinding.tvConfirm.clicks {
            mOnSuccess(this)
        }
    }
}